<!DOCTYPE html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
	<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
	<title>设置-个人信息</title>
	<link rel="icon" href="assets/img/favicon.ico">

	<link rel="stylesheet" type="text/css" href="/css/webbase.css"/>
	<link rel="stylesheet" type="text/css" href="/css/pages-seckillOrder.css"/>
</head>

<body>
<!-- 头部栏位 -->
<!--页面顶部-->
<div id="nav-bottom">
	<!--顶部-->
	<div class="nav-top">
		<div class="top">
			<div class="py-container">
				<div class="shortcut">
					<ul class="fl" th:if="${user==null}">
						<li class="f-item">东东商城欢迎您！</li>
						<li class="f-item">请<a href="/IndexController/toLogin" target="_parent">登录</a>　<span><a
								href="/IndexController/toRegister" target="_blank">免费注册</a></span></li>
					</ul>
					<ul class="fr">
						<li class="f-item">我的订单</li>
						<li class="f-item space"></li>
						<li class="f-item"><a href="home.html" target="_blank">我的东东商城</a></li>
						<li class="f-item space"></li>
						<li class="f-item">东东商城会员</li>
						<li class="f-item space"></li>
						<li class="f-item">企业采购</li>
						<li class="f-item space"></li>
						<li class="f-item">关注东东商城</li>
						<li class="f-item space"></li>
						<li class="f-item" id="service">
							<span>客户服务</span>
							<ul class="service">
								<li><a href="cooperation.html" target="_blank">合作招商</a></li>
								<li><a href="shoplogin.html" target="_blank">商家后台</a></li>
								<li><a href="cooperation.html" target="_blank">合作招商</a></li>
								<li><a href="#">商家后台</a></li>
							</ul>
						</li>
						<li class="f-item space"></li>
						<li class="f-item">网站导航</li>
					</ul>
				</div>
			</div>
		</div>

		<!--头部-->
		<div class="header">
			<div class="py-container">
				<div class="yui3-g Logo">
					<div class="yui3-u Left logoArea">
						<a class="logo-bd" title="东东商城" href="JD-index.html" target="_blank"></a>
					</div>
					<div class="yui3-u Center searchArea">
						<div class="search">
							<form action="" class="sui-form form-inline">
								<!--searchAutoComplete-->
								<div class="input-append">
									<input id="autocomplete" type="text" class="input-error input-xxlarge"/>
									<button class="sui-btn btn-xlarge btn-danger" type="button">搜索</button>
								</div>
							</form>
						</div>
						<div class="hotwords">
							<ul>
								<li class="f-item">东东商城首发</li>
								<li class="f-item">亿元优惠</li>
								<li class="f-item">9.9元团购</li>
								<li class="f-item">每满99减30</li>
								<li class="f-item">亿元优惠</li>
								<li class="f-item">9.9元团购</li>
								<li class="f-item">办公用品</li>

							</ul>
						</div>
					</div>
					<div class="yui3-u Right shopArea">
						<div class="fr shopcar">
							<div class="show-shopcar" id="shopcar">
								<span class="car"></span>
								<a class="sui-btn btn-default btn-xlarge" href="cart.html" target="_blank">
									<span>我的购物车</span>
									<i class="shopnum">0</i>
								</a>
								<div class="clearfix shopcarlist" id="shopcarlist" style="display:none">
									<p>"啊哦，你的购物车还没有商品哦！"</p>
									<p>"啊哦，你的购物车还没有商品哦！"</p>
								</div>
							</div>
						</div>
					</div>
				</div>

				<div class="yui3-g NavList">
					<div class="yui3-u Left all-sort">
						<h4>全部商品分类</h4>
					</div>
					<div class="yui3-u Center navArea">
						<ul class="nav">
							<li class="f-item">服装城</li>
							<li class="f-item">美妆馆</li>
							<li class="f-item">东东超市</li>
							<li class="f-item">全球购</li>
							<li class="f-item">闪购</li>
							<li class="f-item">团购</li>
							<li class="f-item">有趣</li>
							<li class="f-item"><a href="seckill-index.html" target="_blank">秒杀</a></li>
						</ul>
					</div>
					<div class="yui3-u Right"></div>
				</div>
			</div>
		</div>
	</div>
</div>

<script type="text/javascript" src="/js/plugins/jquery/jquery.min.js"></script>
<script type="text/javascript">
	$(function () {
		$("#service").hover(function () {
			$(".service").show();
		}, function () {
			$(".service").hide();
		});
		$("#shopcar").hover(function () {
			$("#shopcarlist").show();
		}, function () {
			$("#shopcarlist").hide();
		});

	})
</script>
<script type="text/javascript" src="/js/plugins/jquery.easing/jquery.easing.min.js"></script>
<script type="text/javascript" src="/js/plugins/sui/sui.min.js"></script>
<script type="text/javascript" src="/js/plugins/jquery-placeholder/jquery.placeholder.min.js"></script>
<script type="text/javascript" src="/js/widget/nav.js"></script>
<script type="text/javascript" src="/pages/userInfo/distpicker.data.js"></script>
<script type="text/javascript" src="/pages/userInfo/distpicker.js"></script>
<script type="text/javascript" src="/pages/userInfo/main.js"></script>
</body>
<!--header-->
<div id="account">
	<div class="py-container">
		<div class="yui3-g home">
			<!--左侧列表-->
			<div class="yui3-u-1-6 list">

				<div class="person-info">
					<div class="person-photo"><img src="/img/_/photo.png" alt=""></div>
					<div class="person-account" th:if="${user != null}">
						<span class="name">[[${user}]]</span>
						<span class="safe">账户安全</span>
					</div>
					<div class="clearfix"></div>
				</div>
				<div class="list-items">
					<dl>
						<dt><i>·</i> 订单中心</dt>
						<dd><a href="home-index.html">我的订单</a></dd>
						<dd><a href="home-order-pay.html">待付款</a></dd>
						<dd><a href="/address/send">待发货</a></dd>
						<dd><a href="home-order-receive.html">待收货</a></dd>
						<dd><a href="home-order-evaluate.html">待评价</a></dd>
					</dl>
					<dl>
						<dt><i>·</i> 我的中心</dt>
						<dd><a href="home-person-collect.html">我的收藏</a></dd>
						<dd><a href="home-person-footmark.html">我的足迹</a></dd>
					</dl>
					<dl>
						<dt><i>·</i> 物流消息</dt>
					</dl>
					<dl>
						<dt><i>·</i> 设置</dt>
						<dd><a href="home-setting-info.html">个人信息</a></dd>
						<dd><a href="home-setting-address.html" class="list-active">地址管理</a></dd>
						<dd><a href="home-setting-safe.html">安全管理</a></dd>
					</dl>
				</div>
			</div>
			<!--右侧主内容-->
			<div class="yui3-u-5-6">
				<div class="body userAddress">
					<div class="address-title">
						<span class="title">地址管理</span>
						<button style="float: right" class="btn btn-info" title="新建" data-toggle="modal"
								data-target="#addeditModal">添加新地址
						</button>
						<span class="clearfix"></span>
					</div>
					<div class="address-detail">
						<table class="sui-table table-bordered">
							<thead>
							<tr>
								<th>姓名</th>
								<th>地址</th>
								<th>联系电话</th>
								<th>操作</th>
							</tr>
							</thead>
							<tbody id="tbodyAddressId">

							</tbody>
						</table>
						<form id="indexForm">
							<a href="javascript:toPage(3)">首页</a>
							<a href="javascript:toPage(1)">上一页</a>
							<a href="javascript:toPage(2)">下一页</a>
							<a href="javascript:toPage(4)">尾页</a>
							第<input type="text" name="pageNum" id="pageNum" size="1px" readonly="readonly">页
							共<input type="text" name="pages" id="pages" size="1px" disabled="disabled">页
							共<input type="text" name="total" id="total" size="1px" disabled="disabled">条
						</form>
					</div>
					<!--新增地址弹出层-->
					<div tabindex="-1" id="addeditModal" role="dialog" data-hasfoot="false"
						 class="sui-modal hide fade edit"
						 style="width:580px;">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×
									</button>
									<h4 id="myModalLabel" class="modal-title">新增地址</h4>
								</div>
								<div class="modal-body">
									<form action="" class="sui-form form-horizontal" id="AddressFormId">
										<div class="control-group">
											<label class="control-label">收货人：</label>
											<div class="controls">
												<input type="text" name="contact" class="input-medium">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">所在地区：</label>
											<div class="controls">
												<div data-toggle="distpicker">
													<div class="form-group area"><!--onchange="city(this.value)"-->
														<select class="form-control" id="province1" name="provinceId"
																onchange="city(this.value)">

														</select>
													</div>
													<div class="form-group area">
														<select class="form-control" id="city1"
																onchange="areas(this.value)"></select>
													</div>
													<div class="form-group area">
														<select class="form-control" id="district1"></select>
													</div>
												</div>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">详细地址：</label>
											<div class="controls">
												<input type="text" name="address" class="input-large">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">联系电话：</label>
											<div class="controls">
												<input type="text" name="mobile" class="input-medium">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">邮箱：</label>
											<div class="controls">
												<input type="text" class="input-medium">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">地址别名：</label>
											<div class="controls">
												<input type="text" name="alias" class="input-medium">
											</div>
											<div class="othername">
												建议填写常用地址：<a href="#" class="sui-btn btn-default">家里</a>　<a href="#"
																										   class="sui-btn btn-default">父母家</a>　<a
													href="#" class="sui-btn btn-default">公司</a>
											</div>
										</div>

									</form>


								</div>
								<div class="modal-footer">
									<button type="button" data-ok="modal" class="sui-btn btn-primary btn-large"
											onclick="insertAddress()">确定
									</button>
									<button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">
										取消
									</button>
								</div>
							</div>
						</div>
					</div>

					<!--编辑窗口（修改窗口）-->
					<div tabindex="-1" role="dialog" data-hasfoot="false" class="sui-modal hide fade update"
						 style="width:580px;">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" data-dismiss="modal" aria-hidden="true" class="sui-close">×
									</button>
									<h4 id="myModalLabel_update" class="modal-title">更新地址</h4>
								</div>
								<div class="modal-body">
									<form action="" class="sui-form form-horizontal" id="updateAddressForm">
										<div class="control-group">
											<label class="control-label">收货人：</label>
											<div class="controls">
												<input type="hidden" id="id">
												<input type="text" id="contact_update" class="input-medium">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">所在地区：</label>
											<div class="controls">
												<div data-toggle="distpicker">
													<div class="form-group area">
														<select class="form-control" id="province2"
																onchange="citytwo(this.value)">

														</select>
													</div>
													<div class="form-group area">
														<select class="form-control" id="city2"
																onchange="areastwo(this.value)">

														</select>
													</div>
													<div class="form-group area">
														<select class="form-control" id="district2">

														</select>
													</div>
												</div>
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">详细地址：</label>
											<div class="controls">
												<input type="text" id="address_update" class="input-large">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">联系电话：</label>
											<div class="controls">
												<input type="text" id="mobile_update" class="input-medium">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">邮箱：</label>
											<div class="controls">
												<input type="text" id="" class="input-medium">
											</div>
										</div>
										<div class="control-group">
											<label class="control-label">地址别名：</label>
											<div class="controls">
												<input type="text" id="alias_update" class="input-medium">
											</div>
											<div class="othername">
												建议填写常用地址：<a href="#" class="sui-btn btn-default">家里</a>　<a href="#"
																										   class="sui-btn btn-default">父母家</a>　<a
													href="#" class="sui-btn btn-default">公司</a>
											</div>
										</div>
									</form>
								</div>
								<div class="modal-footer">
									<button type="button" data-ok="modal" onclick="updateAddress()"
											class="sui-btn btn-primary btn-large">确定
									</button>
									<button type="button" data-dismiss="modal" class="sui-btn btn-default btn-large">
										取消
									</button>
								</div>
							</div>
						</div>
					</div>


				</div>
			</div>
		</div>
	</div>
</div>
<!-- 底部栏位 -->
<!--页面底部-->
<div class="clearfix footer">
	<div class="py-container">
		<div class="footlink">
			<div class="Mod-service">
				<ul class="Mod-Service-list">
					<li class="grid-service-item intro  intro1">

						<i class="serivce-item fl"></i>
						<div class="service-text">
							<h4>正品保障</h4>
							<p>正品保障，提供发票</p>
						</div>

					</li>
					<li class="grid-service-item  intro intro2">

						<i class="serivce-item fl"></i>
						<div class="service-text">
							<h4>正品保障</h4>
							<p>正品保障，提供发票</p>
						</div>

					</li>
					<li class="grid-service-item intro  intro3">

						<i class="serivce-item fl"></i>
						<div class="service-text">
							<h4>正品保障</h4>
							<p>正品保障，提供发票</p>
						</div>

					</li>
					<li class="grid-service-item  intro intro4">

						<i class="serivce-item fl"></i>
						<div class="service-text">
							<h4>正品保障</h4>
							<p>正品保障，提供发票</p>
						</div>

					</li>
					<li class="grid-service-item intro intro5">

						<i class="serivce-item fl"></i>
						<div class="service-text">
							<h4>正品保障</h4>
							<p>正品保障，提供发票</p>
						</div>

					</li>
				</ul>
			</div>
			<div class="clearfix Mod-list">
				<div class="yui3-g">
					<div class="yui3-u-1-6">
						<h4>购物指南</h4>
						<ul class="unstyled">
							<li>购物流程</li>
							<li>会员介绍</li>
							<li>生活旅行/团购</li>
							<li>常见问题</li>
							<li>购物指南</li>
						</ul>

					</div>
					<div class="yui3-u-1-6">
						<h4>配送方式</h4>
						<ul class="unstyled">
							<li>上门自提</li>
							<li>211限时达</li>
							<li>配送服务查询</li>
							<li>配送费收取标准</li>
							<li>海外配送</li>
						</ul>
					</div>
					<div class="yui3-u-1-6">
						<h4>支付方式</h4>
						<ul class="unstyled">
							<li>货到付款</li>
							<li>在线支付</li>
							<li>分期付款</li>
							<li>邮局汇款</li>
							<li>公司转账</li>
						</ul>
					</div>
					<div class="yui3-u-1-6">
						<h4>售后服务</h4>
						<ul class="unstyled">
							<li>售后政策</li>
							<li>价格保护</li>
							<li>退款说明</li>
							<li>返修/退换货</li>
							<li>取消订单</li>
						</ul>
					</div>
					<div class="yui3-u-1-6">
						<h4>特色服务</h4>
						<ul class="unstyled">
							<li>夺宝岛</li>
							<li>DIY装机</li>
							<li>延保服务</li>
							<li>东东商城E卡</li>
							<li>东东商城通信</li>
						</ul>
					</div>
					<div class="yui3-u-1-6">
						<h4>帮助中心</h4>
						<img src="/img/wx_cz.jpg">
					</div>
				</div>
			</div>
			<div class="Mod-copyright">
				<ul class="helpLink">
					<li>关于我们<span class="space"></span></li>
					<li>联系我们<span class="space"></span></li>
					<li>关于我们<span class="space"></span></li>
					<li>商家入驻<span class="space"></span></li>
					<li>营销中心<span class="space"></span></li>
					<li>友情链接<span class="space"></span></li>
					<li>关于我们<span class="space"></span></li>
					<li>营销中心<span class="space"></span></li>
					<li>友情链接<span class="space"></span></li>
					<li>关于我们</li>
				</ul>
				<p>地址：北京市昌平区沙阳路18号 邮编：100000 电话：400-0123-302</p>
				<p>京ICP备08006666号京公网安备11010888888</p>
			</div>
		</div>
	</div>
</div>

<script>
	$(function () {
		getData();
		province();
		provincetwo();
	})

	function getData() {
		$.ajax({
			url: "/address/getAddress",
			dataType: "json",
			data: $("#indexForm").serialize(),//前台向后台传递的参数,没有数据可以不写{id:id}
			type: "post",
			success: function (result) {
				var data = result.data.rows;
				var html = "";
				for (var i = 0; i < data.length; i++) {
					html += "<tr>\n" +
							"<td>" + data[i].contact + "</td>\n" +
							"<td>" + data[i].address + "</td>\n" +
							"<td>" + data[i].mobile + "</td>\n" +
							"<td>\n" +
							"    <a data-toggle='modal' data-target='.update' data-keyboard='false' onclick='toUpdate(" + data[i].id + ")' class='sui-btn  btn-info add-new'>编辑</a>\n" +
							"    <a href=\"javascript:deleteAddress(" + data[i].id + ")\">删除</a>\n" +
							"    <a href=\"#\">设为默认</a>\n" +
							"</td>\n" +
							"</tr>";
				}
				$("#tbodyAddressId").html(html)
				$("#pageNum").val(result.data.pageNum)
				$("#pages").val(result.data.pages)
				$("#total").val(result.data.total)
			}
		})
	}

	/*分页*/
	function toPage(id) {
		var pageNum = parseInt($("#pageNum").val());
		var pages = parseInt($("#pages").val());
		if (id == 1) {
			if (pageNum <= 1) {
				alert("已是首页");
				return;
			}
			$("#pageNum").val(pageNum - 1);
		} else if (id == 2) {
			if (pageNum >= pages) {
				alert("已是尾页");
				return;
			}
			$("#pageNum").val(pageNum + 1);
		} else if (id == 3) {
			$("#pageNum").val(1);
		} else if (id == 4) {
			$("#pageNum").val(pages);
		}
		getData();
	}


	/*回显*/
	function toUpdate(id) {
		alert(id)
		$.ajax({
			url: "/address/toUpdate",
			data: {id: id},
			datatype: "json",
			type: "post",
			success: function (reslut) {
				console.log(reslut)
				var data = reslut.data;
				$("#id").val(data.id)
				$("#contact_update").val(data.contact)
				$("#address_update").val(data.address)
				$("#mobile_update").val(data.mobile)
				$("#alias_update").val(data.alias)
			}
		})
	}

	/*三级联动start*/
	function provincetwo() {
		$.ajax({
			url: "/address/provinces",
			dataType: "json",
			type: "post",
			success: function (result) {
				console.log(result.data)
				var data = result.data;
				var html = "<option value='-1'>---请选择---</option>";
				for (var i = 0; i < data.length; i++) {
					html += "<option value='" + data[i].provinceid + "'>" + data[i].province + "</option>";
				}
				$("#province2").html(html)
			}
		})
	}

	/*市*/
	function citytwo(id) {
		alert("provinceid=" + id)
		$.ajax({
			url: "/address/cities",
			dataType: "json",
			data: {provinceid: id},
			type: "post",
			success: function (result) {
				console.log(result.data)
				var data = result.data;
				var html = "<option value='-1'>---请选择---</option>";
				for (var i = 0; i < data.length; i++) {
					html += "<option value='" + data[i].cityid + "'>" + data[i].city + "</option>";
				}
				$("#city2").html(html)
			}
		})
	}

	/*区*/
	function areastwo(id) {
		alert("cityid=" + id)
		$.ajax({
			url: "/address/areas",
			dataType: "json",
			data: {cityid: id},
			type: "post",
			success: function (result) {
				console.log(result.data)
				var data = result.data;
				var html = "<option value='-1'>---请选择---</option>";
				for (var i = 0; i < data.length; i++) {
					html += "<option value='" +   data[i].areaid   + "'>" + data[i].area + "</option>";
				}
				$("#district2").html(html)
			}
		})
	}

	/*修改*/
	function updateAddress() {
		$.ajax({
			url: "/address/updateAddress",
			dataType: "json",
			data: {
				id: $("#id").val(),
				contact: $("#contact_update").val(),
				provinceId: $("#provinceId_update").val(),
				address: $("#address_update").val(),
				mobile: $("#mobile_update").val(),
				alias: $("#alias_update").val(),
			},
			type: "post",
			success: function (result) {
				console.log(result)
				if (result.code == "666") {
					alert("修改成功")
					window.location.reload();
				} else {
					alert(result.message)
				}
			}, error: function () {
				alert("修改地址失败，请联系管理员")
			}
		})
	}

	/*删除*/
	function deleteAddress(id) {
		alert(id)
		$.ajax({
			url: "/address/delete",
			dataType: "json",
			data: {id: id},
			type: "post",
			success: function (result) {
				if (result.code == "666") {
					alert("删除成功")
					window.location.reload();
				} else {
					alert(result.message)
				}
			}, error: function () {
				alert("删除地址失败，请联系管理员")
			}
		})
	}

	/*三级联动start*/
	function province() {
		$.ajax({
			url: "/address/provinces",
			dataType: "json",
			type: "post",
			success: function (result) {
				console.log(result.data)
				var data = result.data;
				var html = "<option value='-1'>---请选择---</option>";
				for (var i = 0; i < data.length; i++) {
					html += "<option value='" + data[i].provinceid + "'>" + data[i].province + "</option>";
				}
				$("#province1").html(html)
			}
		})
	}

	/*市*/
	function city(id) {
		alert("provinceid=" + id)
		$.ajax({
			url: "/address/cities",
			dataType: "json",
			data: {provinceid: id},
			type: "post",
			success: function (result) {
				console.log(result.data)
				var data = result.data;
				var html = "<option value='-1'>---请选择---</option>";
				for (var i = 0; i < data.length; i++) {
					html += "<option value='" + data[i].cityid + "'>" + data[i].city + "</option>";
				}
				$("#city1").html(html)
			}
		})
	}

	/*区*/
	function areas(id) {
		alert("cityid=" + id)
		$.ajax({
			url: "/address/areas",
			dataType: "json",
			data: {cityid: id},
			type: "post",
			success: function (result) {
				console.log(result.data)
				var data = result.data;
				var html = "<option value='-1'>---请选择---</option>";
				for (var i = 0; i < data.length; i++) {
					html += "<option value='" + data[i].areaid + "'>" + data[i].area + "</option>";
				}
				$("#district1").html(html)
			}
		})
	}


	function insertAddress() {
		$.ajax({
			url: "/address/insertAddress",
			dataType: "json",
			data: $("#AddressFormId").serialize(),
			type: "post",
			success: function (result) {
				if (result.code == "666") {
					alert("增加成功")
					window.location.reload();
				} else {
					alert(result.message)
				}
			}, error: function () {
				alert("地址增加失败,请联系管理员")
			}
		})
	}
</script>


</html>